package org.jsbd.boss.action;

import java.util.List;
import java.util.Map;

import org.jsbd.boss.common.DataGridModel;
import org.jsbd.boss.common.ResponseMapUtils;
import org.jsbd.boss.domian.CabinetConfigBean;
import org.jsbd.boss.service.ICabinetConfigService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/cabinetConfig")
public class CabinetConfigController{

	private static final Logger LOGGER=LoggerFactory.getLogger(CabinetConfigController.class);
	
	@Autowired
	private ICabinetConfigService cabinetConfigService;

	/**
	 * 列表页面
	 * 
	 * @param model
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "listModel")
	public String showCabinetConfigList(Model model) throws Exception {
		return "/qyChannelCabinetConfig/qyChannelCabinetConfigList";
	}

	@RequestMapping(value = "saveCabinetConfig")
	@ResponseBody
	public Object saveCabinetConfig(CabinetConfigBean cabinetConfig){
		cabinetConfig.setDelete(0);
		boolean notExist=cabinetConfigService.validateSaveCabinetConfig(cabinetConfig);
		if(!notExist){
			return ResponseMapUtils.responseFail("机柜名称或ip段已存在，请修改");
		}
		cabinetConfigService.saveCabinetConfig(cabinetConfig);
		return ResponseMapUtils.responseSuccess();
	}

	@RequestMapping(value = "updateCabinetConfig")
	@ResponseBody
	public Object updateCabinetConfig(CabinetConfigBean cabinetConfig){
		boolean notExist=cabinetConfigService.validateUpdateCabinetConfig(cabinetConfig);
		if(!notExist){
			return ResponseMapUtils.responseFail("机柜名称或ip段已存在，请修改");
		}
		cabinetConfigService.updateCabinetConfig(cabinetConfig);
		return ResponseMapUtils.responseSuccess();
	}

	@RequestMapping(value = "getCabinetConfig")
	@ResponseBody
	public CabinetConfigBean getCabinetConfig(CabinetConfigBean cabinetConfig) throws Exception {
		return cabinetConfigService.getCabinetConfig(cabinetConfig);
	}

	@RequestMapping(value = "getCabinetConfigList")
	@ResponseBody
	public List<CabinetConfigBean> getCabinetConfigList(CabinetConfigBean cabinetConfig) throws Exception {
		return cabinetConfigService.getCabinetConfigList(cabinetConfig);
	}

	@RequestMapping(value = "getCabinetConfigListPage")
	@ResponseBody
	public Map<String, Object> getCabinetConfigListPage(DataGridModel page, CabinetConfigBean cabinetConfig) throws Exception {
		return cabinetConfigService.getCabinetConfigListPage(page, cabinetConfig);
	}
	
	@RequestMapping(value = "deleteCabinetConfig")
	@ResponseBody
	public Map<String, Object> deleteCabinetConfig(CabinetConfigBean cabinetConfig) throws Exception {
		cabinetConfigService.deleteCabinetConfig(cabinetConfig);
		return ResponseMapUtils.responseSuccess();
	}
	

}
